package cenas;

import org.anddev.andengine.audio.sound.SoundManager;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import pi.gold.GerenciamentoDeCenas;
import android.content.Context;
import assets.Botao;

public class FimDeJogo extends Scene {
	
	public int largura;
	public int altura;

	GerenciamentoDeCenas trocaDeCenas;

	private BitmapTextureAtlas mapaDeTexturas;
	private TextureRegion regiaoDaTextura, regiaoDaTextura2;

	public FimDeJogo(GerenciamentoDeCenas trocaDeCenas, Context contexto, int largura, int altura, TextureManager tm, SoundManager sm){
		this.trocaDeCenas = trocaDeCenas;
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
		adicionaImagemDeFundoACena(contexto, tm);
		adicionaDizeresACena(contexto, tm);
	}

	public void adicionaImagemDeFundoACena(Context contexto, TextureManager tm) {
		mapaDeTexturas = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		regiaoDaTextura = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, "Cenario.png", 0, 0);
		tm.loadTexture(mapaDeTexturas);
		Sprite cenario = new Sprite(0, 0, regiaoDaTextura);
		attachChild(cenario);
	}

	public void adicionaDizeresACena(Context contexto, TextureManager tm) {
		mapaDeTexturas = new BitmapTextureAtlas(1024, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		regiaoDaTextura2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mapaDeTexturas, contexto, "Fim de jogo.png", 0, 0);
		tm.loadTexture(mapaDeTexturas);
		Sprite informacoes = new Sprite(0, 0, regiaoDaTextura2);
		attachChild(informacoes);
	}

	@Override
	public boolean onSceneTouchEvent(TouchEvent toque) {
		if (toque.getAction() == TouchEvent.ACTION_DOWN) {
			if(toque.getX() >= 240 && toque.getX() < 560){
				if(toque.getY() >= 208 && toque.getY() < 272){
					trocaDeCenas.inicializaNivel();
				}
				if(toque.getY() >= 320 && toque.getY() < 384){
					trocaDeCenas.carregaCena(trocaDeCenas.MENU_PRINCIPAL);
				}
			}
			return true;
		}
		return false;
	}
}
